<template>
  <div class="f f-col h-100 bgImg">
    <div class="h-100 w-100 f j-c a-c">
      <div class="p-50 r-10 bounceInDown animated" style="background:rgba(255,255,255,1);">
     <h1 class="t-c p-b-40 f-22 c666">深圳消消乐后台管理系统</h1>
     <el-form class="p-lr-50" label-width="100px" :model="formLogin">
      <el-form-item label="管理员账号">
        <el-input v-model.trim="formLogin.userCode" placeholder="请输入账号"></el-input>
      </el-form-item>
      <el-form-item label="管理员密码">
        <el-input type="password" v-model.trim="formLogin.passWord" placeholder="请输入密码"></el-input>
      </el-form-item>
      <el-button class="w-100" type="primary" @click="onSubmit">登 录</el-button>
    </el-form>
    </div>

    </div>
    <div>
    </div>
  </div>
</template>

<script>
import { getToken } from "../http/api";
import md5 from "js-md5";
export default {
  name: "login",
  data() {
    return {
      formLogin: {
        userCode: "",
        passWord: ""
      }
    };
  },
  created() {
    this.$store.commit("setUserData", {});
  },
  watch: {},
  methods: {
    onSubmit() {
      if (this.formLogin.userCode == "") {
        this.$message({
          message: "账号不能为空！",
          type: "warning"
        });
        return;
      }
      if (this.formLogin.passWord == "") {
        this.$message({
          message: "密码不能为空！",
          type: "warning"
        });
        return;
      }
      const data = {
        userCode: this.formLogin.userCode,
        passWord: this.formLogin.passWord
      };
      data.passWord = md5(data.passWord);
      getToken(data).then(res => {
        console.log({ 登录: res });
        this.$store.commit("setUserData", res.data);
        this.$message({
          message: "欢迎登陆！",
          type: "success"
        });
        this.$router.push({
          path: "/"
        });
      });
    }
  }
};
</script>
<style scoped>
 .bgImg{ background:url(../assets/img/bg1.jpg) no-repeat;background-size: 100%;} 
</style>
